﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.IO;
using System.Numerics;
using eVoteClient.util;

namespace eVoteClient
{
    public partial class LoadPoll : Form
    {
        public int pollID;
        public LoadPoll() {InitializeComponent();}
        public LoadPoll(int pollID)
        {
            this.pollID = pollID;
            InitializeComponent();
        }

        private void LoadPoll_Load(object sender, EventArgs e)
        {
            
            var socket = global.socket;
            
            socket.writer.WriteLine("POLL_REQ#" + pollID);
            
            socket.writer.Flush();
            
            string reply = socket.reader.ReadLine();
            
            string[] values = reply.Split('#');

            int year = Int32.Parse(values[1].Split('-')[0]);
            int month = Int32.Parse(values[1].Split('-')[1]);
            int day = Int32.Parse(values[1].Split('-')[2]);
            
            var deadline = new DateTime(year, month, day);
            
            if (DateTime.Now < deadline) //deadline has not yet come, OPEN POLL
            {   
                new ViewOpenPoll( pollID, reply).Show();
                
            }
            else
            {
                new ViewClosedPolls(pollID).Show();
                
            }
            this.Hide();
            this.Dispose();

        }
    }
}
